﻿using System.EnterpriseServices;
using System.Linq;
using System.Web.Services;
using Nomad.WebSync.Service.DAO;
using System.Web.Services.Protocols;

namespace Nomad.WebSync.Service {
    public partial class Mobile {
        /// <summary>
        /// Get a list with all contact data from current user
        /// </summary>
        /// <returns>Array of Contact with all contacts data from current user</returns>        
        [SoapHeader("Header"), WebMethod(Description = "Get a list with all contact data from current user")]
        public Contact[] GetContacts() {
            this.Authentication();
            return Contact.ListByAccount(Header.Username);
        }

        /// <summary>
        /// Update or insert a contact info on server
        /// </summary>
        /// <param name="contact">Contact info from mobile</param>
        [SoapHeader("Header"), WebMethod(Description = "Update or insert a contact info on server")]
        public void UpdateContact(Contact contact) {
            this.Authentication();
            contact.Synchronize(Header.Username);
        }

        /// <summary>
        /// Remove a contact info from server
        /// </summary>
        /// <param name="contact">Contact info to be removed</param>
        [SoapHeader("Header"), WebMethod(Description = "Remove a contact info from server")]
        public void RemoveContact(Contact contact) {
            this.Authentication();
            contact.Remove();
        }
    }
}
